//
//  CreateGroupViewController.m
//  RZIM
//
//  Created by reyzhang on 2021/8/12.
//

#import "CreateGroupViewController.h"
#import <SDWebImage/SDWebImage.h>
#import "UIViewController+HUD.h"

#import <YMIMKit/YMIMKit.h>


@interface CreateGroupViewController ()

@end

@implementation CreateGroupViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:249/255.0 green:249/255.0 blue:249/255.0 alpha:1];
    self.createBtn.layer.cornerRadius = 8;
    self.portraitImageView.layer.cornerRadius = 35;
//    self.portraitImageView.backgroundColor = self.createBtn.backgroundColor;
    
    NSString *url = @"https://alifei02.cfp.cn/creative/vcg/800/new/VCG211356100950.jpg";
    [self.portraitImageView sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:nil options:SDWebImageRetryFailed];
   
    if (self.creteType == RoomType) {
        
        self.textLabel.text = @"聊天室名称";
        self.inputTF.placeholder = @"填写聊天室名称（2-10个字符）";
    }
}


- (IBAction)hideKeyboard:(id)sender {
    [[[UIApplication sharedApplication] keyWindow] endEditing:YES];
}

- (IBAction)createGroup:(id)sender {
    
    if (self.creteType == RoomType) {
        
        if (self.inputTF.text.length == 0) {
            [self showHint:@"请输入聊天室名称"];
            return;
        }
        
        [[YMIMClient sharedClient].roomManager
         createRoomWithName:self.inputTF.text portrait:@"https://alifei02.cfp.cn/creative/vcg/800/new/VCG211356100950.jpg"
         uids:self.uidsList
         completion:^(YMRoomInfo * _Nonnull roomInfo, YMErrorCode code) {
            if (code == YM_SUCCESS) {
                NSLog(@"创建聊天室成功， 聊天室id:%@",roomInfo.roomId);
                [self showHint:@"聊天室创建成功"];
                [self.navigationController popToRootViewControllerAnimated:YES];
            }else {
                NSLog(@"聊天室创建失败");
                [self showHint:@"聊天室创建失败"];
            }
        }];
        
    }else{
        
        if (self.inputTF.text.length == 0) {
            [self showHint:@"请输入群名称"];
            return;
        }
        
        [[YMIMClient sharedClient].groupManager
         createGroupWithName:self.inputTF.text portrait:@"https://alifei02.cfp.cn/creative/vcg/800/new/VCG211356100950.jpg"
         uids:self.uidsList
         completion:^(YMGroupInfo * _Nonnull groupInfo, YMErrorCode code) {
            if (code == YM_SUCCESS) {
                NSLog(@"创建群组成功， 群组id:%@",groupInfo.groupId);
                [self showHint:@"创建成功"];
                [self.navigationController popToRootViewControllerAnimated:YES];
            }else {
                NSLog(@"群组创建失败");
                [self showHint:@"群组创建失败"];
            }
        }];
    }
   
    
}
@end
